/**
 * 获取 web 升级信息
 *
 */

export const getWebUpgradeInfo = () => {
  return new Promise((resolve, reject) => {
    fetch('http://123.56.105.128:20099/get-versions')
      .then((response) => {
        if (!response.ok) {
          reject('获取失败')
        }
        resolve(response.json()) // 解析返回的 JSON 数据
      })
      .then((data) => {
        console.log(data) // 处理返回的数据
      })
      .catch((error) => {
        console.error('There was a problem with the fetch operation:', error)
      })
  })
}

// 升级版本
export const upgradeVersion = (name, version) => {
  return new Promise((resolve, reject) => {
    fetch(`http://123.56.105.128:20099/update-versions?name=${name}&version=${version}`)
      .then((response) => {
        if (!response.ok) {
          reject('升级失败')
        }
        resolve(response.json()) // 解析返回的 JSON 数据
      })
      .then((data) => {})
  })
}

// 获取日志
export const getLog = () => {
  return new Promise((resolve, reject) => {
    fetch('http://123.56.105.128:20099/get-log')
      .then((response) => {
        if (!response.ok) {
          reject('获取失败')
        }
        resolve(response.json()) // 解析返回的 JSON 数据
      })
      .then((data) => {
        console.log(data) // 处理返回的数据
      })
  })
}
